package com.app.business.web.business;

import com.app.business.calculate.CalculateHandInMoneyUtils;
import com.app.business.calculate.CalculateUtils;
import com.app.business.model.*;
import com.app.business.service.*;
import com.app.business.utils.AreaAndPriceUtils;
import com.app.business.utils.CalculateDate;
import com.app.system.permission.model.DataDict;
import com.app.system.permission.service.DataDictService;
import com.app.system.utils.CollectionUtils;
import com.app.system.utils.ParamUtils;
import com.app.system.utils.dataType.*;
import com.app.system.utils.dataType.StringUtils;
import com.app.system.utils.exception.Precondition;
import com.app.system.utils.pdf.PdfDocumentGenerator;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.crypto.Data;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.*;

/**
 * 所有单据、协议pdf打印统一接口
 * Created by lsh on 2019/2/14.
 *
 * @author lsh
 */
@Controller
@RequestMapping("/pdf/print/*")
@SuppressWarnings("all")
public class PdfPrintController {

    @Autowired
    private ContractService contractService;
    @Autowired
    private DataDictService dataDictService;
    @Autowired
    private HouseService houseService;
    @Autowired
    private StorageRoomService storageRoomService;
    @Autowired
    private CarLotService carLotService;
    @Autowired
    private ZsProjectService zsProjectService;
    @Autowired
    private BuyHousePersonService buyHousePersonService;
    @Autowired
    private HouseBuyPersonService houseBuyPersonService;
    @Autowired
    private CarLotBuyPersonService carLotBuyPersonService;
    @Autowired
    private StorageRoomPersonService storageRoomPersonService;
    @Autowired
    private OverAreaPriceNewService overAreaPriceNewService;
    @Autowired
    private HandInMoneyService handInMoneyService;
    @Autowired
    private HousePersonForPropertyService housePersonForPropertyServicese;
    @Autowired
    private AdjustAreaService adjustAreaService;

    /**
     * 公共打印方法
     *
     * @param map
     * @param template
     * @param response
     * @throws Exception
     * @throws InvocationTargetException
     * @throws NoSuchMethodException
     * @throws NoSuchFieldException
     * @throws IllegalAccessException
     */
    private void commonPrintPDF(Map map, String template, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        PdfDocumentGenerator pdfDocumentGenerator = new PdfDocumentGenerator();
        OutputStream outputStream = null;
        try {
            response.setHeader("Expires", "0");
            response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
            outputStream = response.getOutputStream();
            pdfDocumentGenerator.generate(template, map, outputStream);
        } catch (IOException e) {

        } finally {

        }
    }

    /**
     * 根据contract自动获取打印模板路径
     * 路径：项目编号/模板
     *
     * @param contract
     * @param templateName
     * @return
     */
    private String getPdfUrl(Contract contract, String templateName) {
        return contract.getTextCode() + "/" + templateName;
    }

    /**
     * 打印房源签认表
     *
     * @param request
     */
    @RequestMapping("chooseResultPDF")
    @RequiresPermissions("print:chooseResultPDF")
    public void chooseResultPDF(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        Map<String, DataDict> houseTypeMap = this.dataDictService.getMapByParentNameForValue("房屋类型");
        Map<String, DataDict> carLotTypeMap = this.dataDictService.getMapByParentNameForValue("车位类型");
        Map<String, DataDict> houseHoldMap = this.dataDictService.getMapByParentNameForValue("房屋户型");
        Map<String, DataDict> houseNatureMap = this.dataDictService.getMapByParentNameForValue("房源属性");
        Map<String, DataDict> jiesuanTypeMap = this.dataDictService.getMapByParentNameForValue("剩余面积是否结算");
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        int type = ParamUtils.getInt(request, "type", 0);
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        List<House> houseList = this.houseService.getHouseListByContractId(contractId);
//        List<House> houseList = this.houseService.getHouseListByContractIdForArea(contractId);
        List<StorageRoom> storageRoomList = this.storageRoomService.getStorageRoomListByContractId(contractId);
        List<CarLot> carLotList = this.carLotService.getCarLotListByContractId(contractId);
        //合并信息备注
        List<AdjustArea> adjustAreaList = this.adjustAreaService.getAdjustAreaListByContractId(contractId);
        String hbMemo = new String();
        if (CollectionUtils.isNotEmpty(adjustAreaList)) {
            for (AdjustArea adjustArea : adjustAreaList) {
                hbMemo = hbMemo + adjustArea.getMemo();
                hbMemo = hbMemo + " ";
            }
        }
        Map map = Maps.newHashMap();
        map.put("bigUtils", new BigDecimalUtils());
        map.put("intUtils", new IntegerUtils());
        map.put("strUtils", new StringUtils());
        map.put("contract", contract);
        map.put("houseList", houseList);
        map.put("storageRoomList", storageRoomList);
        map.put("carLotList", carLotList);
        map.put("houseTypeMap", houseTypeMap);
        map.put("houseHoldMap", houseHoldMap);
        map.put("houseNatureMap", houseNatureMap);
        map.put("carLotTypeMap", carLotTypeMap);
        map.put("jiesuanTypeMap", jiesuanTypeMap);
        map.put("type", type);
        map.put("hbMemo",hbMemo);

        String bsLzMemo = "";
        String bsLzAllMemo = "";
        if (StringUtils.isNotEmpty(contract.getBaoZhangType())) {
            List<String> baoZhangTypeList = Arrays.asList(contract.getBaoZhangType().split(";"));
            for (String s : baoZhangTypeList) {
                bsLzMemo = "";
                if (s.contains("已放弃选择“保障区”")) {
                    if (s.substring(10, 14).equals("0302")) {
                        bsLzMemo = "流转三房二厅：";
                        bsLzMemo = bsLzMemo + org.apache.commons.lang3.StringUtils.substringBetween(s, "的", "被");
                    } else if (s.substring(10, 14).equals("0402")) {
                        bsLzMemo = "流转四房二厅：";
                        bsLzMemo = bsLzMemo + org.apache.commons.lang3.StringUtils.substringBetween(s, "的", "被");
                    }
                    bsLzMemo = bsLzMemo + "<br/>";
                }
                bsLzAllMemo = bsLzAllMemo + bsLzMemo;
            }
        }
        map.put("bsLzAllMemo", bsLzAllMemo);

        //房源签认表
        String template = this.getPdfUrl(contract, "chooseResultPDF.html");
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 打印房源签认表
     *
     * @param request
     */
    @RequestMapping("chooseResultYxPDF")
    public void chooseResultYxPDF(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        Map<String, DataDict> houseTypeMap = this.dataDictService.getMapByParentNameForValue("房屋类型");
        Map<String, DataDict> carLotTypeMap = this.dataDictService.getMapByParentNameForValue("车位类型");
        Map<String, DataDict> houseHoldMap = this.dataDictService.getMapByParentNameForValue("房屋户型");
        Map<String, DataDict> houseNatureMap = this.dataDictService.getMapByParentNameForValue("房源属性");
        Map<String, DataDict> jiesuanTypeMap = this.dataDictService.getMapByParentNameForValue("剩余面积是否结算");
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        int type = ParamUtils.getInt(request, "type", 0);
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        List<House> houseList = this.houseService.getHouseListByContractId(contractId);
//        List<House> houseList = this.houseService.getHouseListByContractIdForArea(contractId);
        List<StorageRoom> storageRoomList = this.storageRoomService.getStorageRoomListByContractId(contractId);
        List<CarLot> carLotList = this.carLotService.getCarLotListByContractId(contractId);
        //合并信息备注
        List<AdjustArea> adjustAreaList = this.adjustAreaService.getAdjustAreaListByContractId(contractId);
        String hbMemo = new String();
        if (CollectionUtils.isNotEmpty(adjustAreaList)) {
            for (AdjustArea adjustArea : adjustAreaList) {
                hbMemo = hbMemo + adjustArea.getMemo();
                hbMemo = hbMemo + " ";
            }
        }
        Map map = Maps.newHashMap();
        map.put("bigUtils", new BigDecimalUtils());
        map.put("intUtils", new IntegerUtils());
        map.put("strUtils", new StringUtils());
        map.put("contract", contract);
        map.put("houseList", houseList);
        map.put("storageRoomList", storageRoomList);
        map.put("carLotList", carLotList);
        map.put("houseTypeMap", houseTypeMap);
        map.put("houseHoldMap", houseHoldMap);
        map.put("houseNatureMap", houseNatureMap);
        map.put("carLotTypeMap", carLotTypeMap);
        map.put("jiesuanTypeMap", jiesuanTypeMap);
        map.put("type", type);
        map.put("hbMemo",hbMemo);

        String bsLzMemo = "";
        String bsLzAllMemo = "";
        if (StringUtils.isNotEmpty(contract.getBaoZhangType())) {
            List<String> baoZhangTypeList = Arrays.asList(contract.getBaoZhangType().split(";"));
            for (String s : baoZhangTypeList) {
                bsLzMemo = "";
                if (s.contains("已放弃选择“保障区”")) {
                    if (s.substring(10, 14).equals("0302")) {
                        bsLzMemo = "流转三房二厅：";
                        bsLzMemo = bsLzMemo + org.apache.commons.lang3.StringUtils.substringBetween(s, "的", "被");
                    } else if (s.substring(10, 14).equals("0402")) {
                        bsLzMemo = "流转四房二厅：";
                        bsLzMemo = bsLzMemo + org.apache.commons.lang3.StringUtils.substringBetween(s, "的", "被");
                    }
                    bsLzMemo = bsLzMemo + "<br/>";
                }
                bsLzAllMemo = bsLzAllMemo + bsLzMemo;
            }
        }
        map.put("bsLzAllMemo", bsLzAllMemo);

        //房源签认表
        String template = this.getPdfUrl(contract, "chooseResultYxPDF.html");
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 打印书证材料具结书
     *
     * @param request
     */
    @RequestMapping("paperForJjsPDF")
    public void paperForJjsPDF(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map map = Maps.newHashMap();
        map.put("contract", contract);
        map.put("bigUtils", new BigDecimalUtils());
        map.put("intUtils", new IntegerUtils());
        map.put("strUtils", new StringUtils());
        String template = this.getPdfUrl(contract, "paperForJjsPrintPDF.html"); //交房通知书
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 财务复核时打印提前交付申请表打印
     *
     * @param request
     */
    @RequestMapping("advanceTakeHousePrintPDF")
    @RequiresPermissions("print:advanceTakeHousePrintPDF")
    public void advanceTakeHousePrintPDF(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        Map<String, DataDict> houseNatureMap = this.dataDictService.getMapByParentNameForValue("房源属性");

        int contractId = ParamUtils.getInt(request, "contractId", 0);
        String houseIdStr = ParamUtils.getString(request, "houseIdStr", "");
        String carLotIdStr = ParamUtils.getString(request, "carLotIdStr", "");
        String storageRoomIdStr = ParamUtils.getString(request, "storageRoomIdStr", "");
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        List<House> houseAllList = Lists.newLinkedList();
        List<House> houseSyList = Lists.newLinkedList();
        List<House> houseList = Lists.newLinkedList();
        List<StorageRoom> storageRoomList = Lists.newLinkedList();
        List<CarLot> carLotList = Lists.newLinkedList();
        BigDecimal syHouseArea = BigDecimal.ZERO;
        houseAllList = this.houseService.getHouseListByContractId(contract.getId());
        if (!CollectionUtils.isEmpty(houseAllList)) {
            for (House house : houseAllList) {
                if (!houseIdStr.contains(house.getId().toString())) {
                    houseSyList.add(house);
                    syHouseArea = BigDecimalUtils.getSum(syHouseArea, house.getBuildArea());
                }
            }
        }

        //如果没有选择，则显示所有房源、储物间、车位
        if (houseIdStr.equals("") && carLotIdStr.equals("") && storageRoomIdStr.equals("")) {
            houseList = this.houseService.getHouseListByContractId(contract.getId());
            storageRoomList = this.storageRoomService.getStorageRoomListByContractId(contract.getId());
            carLotList = this.carLotService.getCarLotListByContractId(contract.getId());
        } else {
            if (houseIdStr.length() > 0) {
                houseList = this.houseService.getHouseListByIds(houseIdStr);
            }
            if (carLotIdStr.length() > 0) {
                carLotList = this.carLotService.getCarLotListByIds(carLotIdStr);
            }
            if (storageRoomIdStr.length() > 0) {
                storageRoomList = this.storageRoomService.getStorageRoomListByIds(storageRoomIdStr);
            }
        }

        Map map = Maps.newHashMap();
        map.put("moneyArea", BigDecimalUtils.getBigAndBigSub(syHouseArea, contract.getZzResultArea()));
        map.put("houseNatureMap", houseNatureMap);
        map.put("contract", contract);
        map.put("houseList", houseList);
        map.put("houseAllList", houseAllList);
        map.put("houseSyList", houseSyList);
        map.put("storageRoomList", storageRoomList);
        map.put("carLotList", carLotList);
        map.put("bigUtils", new BigDecimalUtils());
        map.put("intUtils", new IntegerUtils());
        map.put("strUtils", new StringUtils());
        Map<String, List<Map>> buyHousePersonHouseMap = this.buyHousePersonService.getBuyHousePersonByHouse();
        Map<String, List<Map>> buyHousePersonCarLotMap = this.buyHousePersonService.getBuyHousePersonByCarLot();
        Map<String, List<Map>> buyHousePersonStorageRoomMap = this.buyHousePersonService.getBuyHousePersonByStorageRoom();
        map.put("buyHousePersonHouseMap", buyHousePersonHouseMap);
        map.put("buyHousePersonCarLotMap", buyHousePersonCarLotMap);
        map.put("buyHousePersonStorageRoomMap", buyHousePersonStorageRoomMap);

        //部分交房计算金额
        Map handMoneyMap = CalculateHandInMoneyUtils.calPartTakeHouseMoney(contract, houseList, carLotList);
        map.put("handMoneyMap", handMoneyMap);

        //申请提前交房
//        String template = this.getPdfUrl(contract, "advanceTakeHousePDF.html");
        String template = this.getPdfUrl(contract, "buChongAgreementPrintPDF.html");
        this.commonPrintPDF(map, template, response);
    }


    /**
     * 打印财务结算表
     *
     * @param request
     */
    @RequestMapping("settlementPDF")
    @RequiresPermissions("print:settlementPDF")
    public void settlementPDF(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null && contract.getZsProject() != null, "数据有误！");
        Map<String, DataDict> jiesuanTypeMap = this.dataDictService.getMapByParentNameForValue("剩余面积是否结算");
        Map<String, Map> overHouseMoneyMap = this.overAreaPriceNewService.getOverHouseMoneyMap(contract);
        Map map = Maps.newHashMap();
        String gdbzPrice = null;
        if (contract.getIsDoubleMoney() != null && contract.getIsDoubleMoney() == 0) {
            Integer month = CalculateDate.getDatesForMonth(contract.getTkDate(), contract.getChooseHouseDate());
            //住宅临时安置补助费
            if (month > 36) {
                gdbzPrice = BigDecimalUtils.getNotNullStr(BigDecimalUtils.getBigAndBigMul(new BigDecimal("2"), contract.getParameter().getGdbzPrice()));   //发两个月的周转费
            } else {
                gdbzPrice = BigDecimalUtils.getNotNullStr(contract.getParameter().getGdbzPrice());   //发一个月的周转费
            }
        }
        //手动计算
        else {
            //单倍
            if (contract.getIsDoubleMoney() != null && contract.getIsDoubleMoney() == 1) {
                gdbzPrice = BigDecimalUtils.getNotNullStr(contract.getParameter().getGdbzPrice());   //发一个月的周转费
            }
            //双倍
            else if (contract.getIsDoubleMoney() != null && contract.getIsDoubleMoney() == 2) {
                gdbzPrice = BigDecimalUtils.getNotNullStr(BigDecimalUtils.getBigAndBigMul(new BigDecimal("2"), contract.getParameter().getGdbzPrice()));   //发两个月的周转费
            }
        }

        //若储物间正常调换，得到调换后的面积 即：储物间置换面积 = 储物间面积 * 储物间单价 * 应补差价
        BigDecimal storageSubArea = BigDecimal.ZERO; //用来抵储物间的安置面积
        if (!String.valueOf(contract.getBuyStorageRoomType()).equals(null) && contract.getBuyStorageRoomType() == 1) {
            storageSubArea = BigDecimalUtils.getBigAndBigDiv(contract.getStorageRoomArea(), contract.getParameter().getCwjBl(), 2);
        }

        //合并信息备注
        List<AdjustArea> adjustAreaList = this.adjustAreaService.getAdjustAreaListByContractId(contractId);
        String hbMemo = new String();
        if (CollectionUtils.isNotEmpty(adjustAreaList)) {
            for (AdjustArea adjustArea : adjustAreaList) {
                hbMemo = hbMemo + adjustArea.getMemo();
                hbMemo = hbMemo + " ";
            }
        }
        map.put("storageSubArea", storageSubArea);
        map.put("bigUtils", new BigDecimalUtils());
        map.put("intUtils", new IntegerUtils());
        map.put("strUtils", new StringUtils());
        map.put("contract", contract);
        map.put("zsProject", contract.getZsProject());
        map.put("parameter", contract.getParameter());
        map.put("gdbzPrice", gdbzPrice);
        map.put("overHouseMoneyMap", overHouseMoneyMap);
        map.put("jiesuanTypeMap", jiesuanTypeMap);
        map.put("hbMemo",hbMemo);
        map.put("adjustAreaList",adjustAreaList);



        //期房部分备注
        Map cwMemoMap = CalculateHandInMoneyUtils.calQiHouseMoney(contract);
        map.put("cwMemoMap", cwMemoMap);
        if (contract.getParameter().getGwjHouseNowBl() != null && contract.getParameter().getGwjHouseNowBl().compareTo(BigDecimal.ZERO) > 0) {
            //公维金展示
            Map gwjMoneyMap = CalculateHandInMoneyUtils.calGwjMoney(contract);
            map.put("gwjXianFangMoneyMap", gwjMoneyMap.get("现房"));
            map.put("gwjQiFangMoneyMap", gwjMoneyMap.get("期房"));
        }

        //财务结算表
        String template = this.getPdfUrl(contract, "settlementPDF.html");
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 打印缴款清单
     *
     * @param request
     */
    @RequestMapping("paymentPDF")
    @RequiresPermissions("print:paymentPDF")
    public void paymentPDF(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map map = Maps.newHashMap();
        map.put("contract", contract);
        map.put("bigUtils", new BigDecimalUtils());
        map.put("intUtils", new IntegerUtils());
        map.put("strUtils", new StringUtils());

        //缴款清单
        String template = this.getPdfUrl(contract, "paymentPDF.html");
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 打印交房通知书
     *
     * @param request
     */
    @RequestMapping("takeHousePrintPDF")
    @RequiresPermissions("print:takeHousePrintPDF")
    public void takeHousePrintPDF(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        List<String> personNameList = this.buyHousePersonService.getHouseNameList(contract.getId(), 2);
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map map = Maps.newHashMap();
        map.put("personNameList", personNameList);
        map.put("contract", contract);
        map.put("strUtils", new StringUtils());
        String template = this.getPdfUrl(contract, "takeHousePDF.html"); //交房通知书
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 打印交房告知书
     *
     * @param request
     */
    @RequestMapping("takeHouseGZPDF")
    @RequiresPermissions("print:takeHouseGZPDF")
    public void takeHouseGZPDF(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map map = Maps.newHashMap();
        List<String> personNameList = this.buyHousePersonService.getHouseNameList(contract.getId(), 1);

        if (contract.getChooseHouseDate() != null) {
            int days = DateUtils.getDaysByDateAndDate(contract.getZsProject().getStartYear(), DateUtils.stringToDateDefault(DateUtils.dateToStringDefault(contract.getChooseHouseDate())));
            Date date = DateUtils.getDateByDateAndDays(contract.getZsProject().getTakeHouseDate(), days);
            map.put("dateStr", DateUtils.dateToStringFormat(date, "yyyy年MM月dd日"));
        }
        map.put("personNameList", personNameList);
        map.put("contract", contract);
        map.put("strUtils", new StringUtils());
        String template = this.getPdfUrl(contract, "takeHouseGZPDF.html"); //交房通知书
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 打印继承具结文本
     *
     * @param request
     */
    @RequestMapping("houseInheritPDF")
    @RequiresPermissions("print:houseInheritPDF")
    public void houseInheritPDF(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map map = Maps.newHashMap();
        map.put("contract", contract);
        map.put("strUtils", new StringUtils());
        String template = this.getPdfUrl(contract, "houseInheritPDF.html"); //交房通知书
        this.commonPrintPDF(map, template, response);
    }


    /**
     * 打印赠与具结文本
     *
     * @param request
     */
    @RequestMapping("houseGiftPDF")
    @RequiresPermissions("print:houseGiftPDF")
    public void houseGiftPDF(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map map = Maps.newHashMap();
        map.put("contract", contract);
        map.put("strUtils", new StringUtils());
        String template = this.getPdfUrl(contract, "houseGiftPDF.html"); //交房通知书
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 打印缴款通知书
     *
     * @param request
     */
    @RequestMapping("handInMoneyPrintPDF")
    @RequiresPermissions("print:handInMoneyPrintPDF")
    public void handInMoneyPrintPDF(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map map = Maps.newHashMap();
        map.put("contract", contract);
        map.put("strUtils", new StringUtils());
        map.put("bigUtils", new BigDecimalUtils());

        String template = this.getPdfUrl(contract, "handInMoneyPDF.html"); //缴款通知书
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 住宅专项维修基金
     * 打印缴款通知书
     *
     * @param request
     */
    @RequestMapping("handInMoneyWxjPrintPDF")
    public void handInMoneyWxjPrintPDF(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map map = Maps.newHashMap();
        map.put("contract", contract);
        map.put("strUtils", new StringUtils());
        map.put("bigUtils", new BigDecimalUtils());
        List<House> houseList = this.houseService.getHouseListByContractId(contract.getId());
        Map<String, BigDecimal> getGwjMapByAzName = this.houseService.getGwjMapByAzName(houseList);//安置区对应公维金
        Map<String,Map> jkInfoMap = this.houseService.jkInfo();//安置区对应账号信息

        List<Map> mapList = new LinkedList<>();
        if (getGwjMapByAzName != null) {
            for (String key : getGwjMapByAzName.keySet()) {
                Map jkInfoItem = jkInfoMap.get(key);
                jkInfoItem.put("gwj",getGwjMapByAzName.get(key));
                jkInfoItem.put("key",key);
                mapList.add(jkInfoItem);
            }
        }
        map.put("mapList",mapList);
        String template = this.getPdfUrl(contract, "handInMoneyWxjPrintPDF.html"); //缴款通知书
        this.commonPrintPDF(map, template, response);
    }
    /**
     * 选房通知单pdf打印
     *
     * @param request
     */
    @RequestMapping("batchChooseNoticePrintPDF")
    @RequiresPermissions("print:batchChooseNoticePrintPDF")
    public void batchChooseNoticePrintPDF(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int type = ParamUtils.getInt(request, "type", 0);
        String preChooseDate = ParamUtils.getString(request, "preChooseDate", "");
        int zsProjectId = ParamUtils.getInt(request, "zsProjectId", 0);
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Map<String, DataDict> betweenChooseDateMap = this.dataDictService.getMapByParentNameForValue("安排选房时间段");

        Contract contract = null;
        List<Contract> contractList = new ArrayList<>();//待打印的基础信息list
        if (type == 1) {//单独打印
            contract = this.contractService.findOne(contractId);
            Precondition.checkSqdsArguement(contract != null, "数据错误，请重试！");
            contractList.add(contract);
        } else if (type == 2) {
            Precondition.checkSqdsArguement(zsProjectId != 0, "数据错误!");
        }

        if (StringUtils.isNotEmpty(preChooseDate)) {//批量打印
            contractList = this.contractService.getContractListByZsProjectIdAndPreChooseDate(zsProjectId, preChooseDate);
        }

        Precondition.checkSqdsArguement(contractList.size() > 0, "无协议!");
        DateUtils dateUtils = new DateUtils();

        Map map = Maps.newHashMap();
        map.put("contractList", contractList);
        map.put("dateUtils", dateUtils);
        map.put("strUtils", new StringUtils());
        map.put("betweenChooseDateMap", betweenChooseDateMap);

        String template = this.getPdfUrl(contractList.get(0), "batchChooseNoticePrintPDF.html"); //选房通知单模板
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 安置协议打印1
     *
     * @param request
     */
    @RequestMapping("resetAgreementPrintPDF1")
    @RequiresPermissions("print:resetAgreementPrintPDF1")
    public void resetAgreementPrintPDF1(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map map = Maps.newHashMap();
        map.put("contract", contract);
        map.put("strUtils", new StringUtils());
        map.put("intUtils", new IntegerUtils());

        String template = this.getPdfUrl(contract, "resetAgreementPrintPDF1.html");
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 安置协议打印2
     *
     * @param request
     */
    @RequestMapping("resetAgreementPrintPDF2")
    @RequiresPermissions("print:resetAgreementPrintPDF2")
    public void resetAgreementPrintPDF2(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int houseId = ParamUtils.getInt(request, "houseId", 0);
        House house = this.houseService.findOne(houseId);
        Precondition.checkSqdsArguement(house != null && house.getAzProject() != null, "房源数据有误！");
        Contract contract = house.getContract();
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        StorageRoom storageRoom = this.storageRoomService.getStorageRoomByHouseId(house.getId());
        storageRoom = storageRoom == null ? new StorageRoom() : storageRoom;
        List<String> ids = this.houseBuyPersonService.getBuyHousePersonIdListByHouseId(house.getId());
        List<BuyHousePerson> buyHousePersonList = new ArrayList<>();
        if (ids.size() != 0) {
            buyHousePersonList = this.buyHousePersonService.getBuyHousePersonListByBuyHousePersonId(ids, contract.getId());
        }
        Map<String, String> townMap = this.dataDictService.getMapByParentNameForValue_Name("乡镇");
        Map map = Maps.newHashMap();
        map.put("size", ids.size());
        map.put("buyHousePersonList", buyHousePersonList);
        map.put("contract", contract);
        map.put("townMap", townMap);
        map.put("house", house);
        map.put("azProject", house.getAzProject());
        map.put("storageRoom", storageRoom);
        map.put("strUtils", new StringUtils());
        map.put("bigUtils", new BigDecimalUtils());

        String template = this.getPdfUrl(contract, "resetAgreementPrintPDF2.html");
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 单选储物间打印
     *
     * @param request
     */
    @RequestMapping("storageRoomPrintPDF")
    @RequiresPermissions("print:storageRoomPrintPDF")
    public void storageRoomPrintPDF(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int storageRoomId = ParamUtils.getInt(request, "storageRoomId", 0);
        StorageRoom storageRoom = this.storageRoomService.findOne(storageRoomId);
        Precondition.checkSqdsArguement(storageRoom != null && storageRoom.getAzProject() != null, "房源数据有误！");
        Contract contract = storageRoom.getContract();
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        List<String> ids = this.storageRoomPersonService.getBuyHousePersonIdListByStorageRoomId(storageRoom.getId());
        List<BuyHousePerson> buyHousePersonList = new ArrayList<>();
        if (ids.size() != 0) {
            buyHousePersonList = this.buyHousePersonService.getBuyHousePersonListByBuyHousePersonId(ids, contract.getId());
        }
        Map<String, String> townMap = this.dataDictService.getMapByParentNameForValue_Name("乡镇");
        Map map = Maps.newHashMap();
        map.put("contract", contract);
        map.put("size", ids.size());
        map.put("townMap", townMap);
        map.put("buyHousePersonList", buyHousePersonList);
        map.put("azProject", storageRoom.getAzProject());
        map.put("storageRoom", storageRoom);
        map.put("strUtils", new StringUtils());
        map.put("bigUtils", new BigDecimalUtils());

        String template = this.getPdfUrl(contract, "storageRoomPrintPDF.html");
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 车位使用权买卖协议打印
     *
     * @param request
     */
    @RequestMapping("carLotPrintPDF")
    @RequiresPermissions("print:carLotPrintPDF")
    public void carLotPrintPDF(HttpServletRequest request, HttpServletResponse response) throws Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int carId = ParamUtils.getInt(request, "carId", 0);
        CarLot carLot = this.carLotService.findOne(carId);
        Precondition.checkSqdsArguement(carLot != null, "房源数据有误！");
        Contract contract = carLot.getContract();
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map<String, DataDict> carLotTypeMap = this.dataDictService.getMapByParentNameForValue("车位类型");
        Map<String, String> townMap = this.dataDictService.getMapByParentNameForValue_Name("乡镇");
        List<String> ids = this.carLotBuyPersonService.getBuyHousePersonIdListByCarLotId(carLot.getId());
        List<BuyHousePerson> buyHousePersonList = new ArrayList<>();
        if (ids.size() != 0) {
            buyHousePersonList = this.buyHousePersonService.getBuyHousePersonListByBuyHousePersonId(ids, contract.getId());
        }
        Map map = Maps.newHashMap();
        map.put("size", ids.size());
        map.put("buyHousePersonList", buyHousePersonList);
        map.put("contract", contract);
        map.put("townMap", townMap);
        map.put("carLot", carLot);
        map.put("carLotTypeMap", carLotTypeMap);
        map.put("strUtils", new StringUtils());
        map.put("bigUtils", new BigDecimalUtils());
        map.put("intUtils", new IntegerUtils());
        String template = "";
        if (carLot.getCarLotType() != null) {

            template = this.getPdfUrl(contract, "carLotPrintPDF.html");
            if (carLot.getCarLotType() == 4 || carLot.getCarLotType() == 5 || carLot.getCarLotType() == 6 || carLot.getCarLotType() == 8) {
                template = this.getPdfUrl(contract, "carLotPrintLeasePDF.html");
            }
        }
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 选房安置告知书
     *
     * @param request
     */
    @RequestMapping("chooseHouseGzPDF")
    @RequiresPermissions("print:chooseHouseGzPDF")
    public void chooseHouseGzPDF(HttpServletRequest request, HttpServletResponse response) throws
            Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int type = ParamUtils.getInt(request, "type", 0);
        String preChooseDate = ParamUtils.getString(request, "preChooseDate", "");
        int zsProjectId = ParamUtils.getInt(request, "zsProjectId", 0);
        int contractId = ParamUtils.getInt(request, "contractId", 0);

        Contract contract = null;
        List<Contract> contractList = new ArrayList<>();//待打印的基础信息list
        if (type == 1) {//单独打印
            contract = this.contractService.findOne(contractId);
            Precondition.checkSqdsArguement(contract != null, "数据错误，请重试！");
            contractList.add(contract);
        } else if (type == 2) {
            Precondition.checkSqdsArguement(zsProjectId != 0, "数据错误!");
        }

        if (StringUtils.isNotEmpty(preChooseDate)) {//批量打印
            contractList = this.contractService.getContractListByZsProjectIdAndPreChooseDate(zsProjectId, preChooseDate);
        }

        Precondition.checkSqdsArguement(contractList.size() > 0, "无协议!");
        Map map = Maps.newHashMap();
        map.put("contractList", contractList);
        map.put("strUtils", new StringUtils());
        String template = this.getPdfUrl(contractList.get(0), "chooseHouseGzBillPDF.html");
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 选房安置资格审查表打印
     *
     * @param request
     */
    @RequestMapping("chooseHouseReviewTablePDF")
    @RequiresPermissions("print:chooseHouseReviewTablePDF")
    public void chooseHouseReviewTablePDF(HttpServletRequest request, HttpServletResponse response) throws
            Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        Map<String, DataDict> groupMap = this.dataDictService.getMapByParentNameForValue("组别");
        int type = ParamUtils.getInt(request, "type", 0);
        String preChooseDate = ParamUtils.getString(request, "preChooseDate", "");
        int zsProjectId = ParamUtils.getInt(request, "zsProjectId", 0);
        int contractId = ParamUtils.getInt(request, "contractId", 0);

        Contract contract = null;
        List<Contract> contractList = new ArrayList<>();//待打印的基础信息list
        if (type == 1) {//单独打印
            contract = this.contractService.findOne(contractId);
            Precondition.checkSqdsArguement(contract != null, "数据错误，请重试！");
            contractList.add(contract);
        } else if (type == 2) {
            Precondition.checkSqdsArguement(zsProjectId != 0, "数据错误!");
        }

        if (StringUtils.isNotEmpty(preChooseDate)) {//批量打印
            contractList = this.contractService.getContractListByZsProjectIdAndPreChooseDate(zsProjectId, preChooseDate);
        }

        Precondition.checkSqdsArguement(contractList.size() > 0, "无协议!");
        Map map = Maps.newHashMap();
        map.put("contractList", contractList);
        map.put("groupMap", groupMap);
        map.put("intUtils", new IntegerUtils());
        map.put("strUtils", new StringUtils());
        String template = this.getPdfUrl(contractList.get(0), "chooseHouseReviewTablePDF.html");
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 安置流程卡打印
     *
     * @param request
     */
    @RequestMapping("resetProcessCardPDF")
    @RequiresPermissions("print:resetProcessCardPDF")
    public void resetProcessCardPDF(HttpServletRequest request, HttpServletResponse response) throws
            Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int type = ParamUtils.getInt(request, "type", 0);
        String preChooseDate = ParamUtils.getString(request, "preChooseDate", "");
        int zsProjectId = ParamUtils.getInt(request, "zsProjectId", 0);
        int contractId = ParamUtils.getInt(request, "contractId", 0);

        Contract contract = null;
        List<Contract> contractList = new ArrayList<>();//待打印的基础信息list
        if (type == 1) {//单独打印
            contract = this.contractService.findOne(contractId);
            Precondition.checkSqdsArguement(contract != null, "数据错误，请重试！");
            contractList.add(contract);
        } else if (type == 2) {
            Precondition.checkSqdsArguement(zsProjectId != 0, "数据错误!");
        }

        if (StringUtils.isNotEmpty(preChooseDate)) {//批量打印
            contractList = this.contractService.getContractListByZsProjectIdAndPreChooseDate(zsProjectId, preChooseDate);
        }

        Precondition.checkSqdsArguement(contractList.size() > 0, "无协议!");
        Map map = Maps.newHashMap();
        map.put("contractList", contractList);
        map.put("strUtils", new StringUtils());
        map.put("intUtils", new IntegerUtils());

        String template = this.getPdfUrl(contractList.get(0), "resetProcessCardPDF.html");
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 打印结清凭证
     *
     * @param request
     */
    @RequestMapping("settleVoucherPDF")
    @RequiresPermissions("print:settleVoucherPDF")
    public void settleVoucherPDF(HttpServletRequest request, HttpServletResponse response) throws
            Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map<String, DataDict> handInMoneyMap = this.dataDictService.getMapByParentNameForValue("缴款类别");

        List<HandInMoney> handInMoneyList = this.handInMoneyService.getHandInMoneyListByContractId(contractId);

        Map map = Maps.newHashMap();
        map.put("contract", contract);
        map.put("bigUtils", new BigDecimalUtils());
        map.put("intUtils", new IntegerUtils());
        map.put("strUtils", new StringUtils());
        map.put("moneyUtils", new MoneyUtils());
        map.put("handInMoneyMap", handInMoneyMap);
        map.put("handInMoneyList", handInMoneyList);

        //缴款合计  公维金先缴
        BigDecimal yjMoney = BigDecimal.ZERO;

        if (contract.getHouseFinalNoWxjMoney().compareTo(BigDecimal.ZERO) < 0) {
            yjMoney = BigDecimalUtils.getSum(yjMoney,contract.getHouseFinalNoWxjMoney());
        }

        //公维金肯定为负数
        yjMoney = BigDecimalUtils.getSum(yjMoney,contract.getZzwxMoney());
        map.put("yjMoney",yjMoney);
        //缴款清单
        String template = this.getPdfUrl(contract, "settleVoucherPDF.html");
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 打印户型清单
     *
     * @param request
     */
    @RequestMapping("houseTypeListPDF")
    @RequiresPermissions("print:houseTypeListPDF")
    public void houseTypeListPDF(HttpServletRequest request, HttpServletResponse response) throws
            Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        String houseIdStr = ParamUtils.getString(request, "houseIdStr", "");
        String carLotIdStr = ParamUtils.getString(request, "carLotIdStr", "");
        String storageRoomIdStr = ParamUtils.getString(request, "storageRoomIdStr", "");
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        List<House> houseList = Lists.newLinkedList();
        List<StorageRoom> storageRoomList = Lists.newLinkedList();
        List<CarLot> carLotList = Lists.newLinkedList();
        //如果没有选择，则显示所有房源、储物间、车位
        if (houseIdStr.equals("") && carLotIdStr.equals("") && storageRoomIdStr.equals("")) {
            houseList = this.houseService.getHandInMoneyHouseListByContractId(contract.getId());
            storageRoomList = this.storageRoomService.getStorageRoomListByContractId(contract.getId());
            carLotList = this.carLotService.getHandInMoneyCarLotListByContractId(contract.getId());
        } else {
            if (houseIdStr.length() > 0) {
                houseList = this.houseService.getHouseListByIds(houseIdStr);
            }
            if (carLotIdStr.length() > 0) {
                carLotList = this.carLotService.getCarLotListByIds(carLotIdStr);
            }
            if (storageRoomIdStr.length() > 0) {
                storageRoomList = this.storageRoomService.getStorageRoomListByIds(storageRoomIdStr);
            }
        }

        Map map = Maps.newHashMap();
        map.put("contract", contract);
        map.put("houseList", houseList);
        map.put("storageRoomList", storageRoomList);
        map.put("carLotList", carLotList);
        map.put("bigUtils", new BigDecimalUtils());
        map.put("intUtils", new IntegerUtils());
        map.put("strUtils", new StringUtils());
        Map<String, List<Map>> buyHousePersonHouseMap = this.buyHousePersonService.getBuyHousePersonByHouse();
        Map<String, List<Map>> buyHousePersonCarLotMap = this.buyHousePersonService.getBuyHousePersonByCarLot();
        Map<String, List<Map>> buyHousePersonStorageRoomMap = this.buyHousePersonService.getBuyHousePersonByStorageRoom();
        map.put("buyHousePersonHouseMap", buyHousePersonHouseMap);
        map.put("buyHousePersonCarLotMap", buyHousePersonCarLotMap);
        map.put("buyHousePersonStorageRoomMap", buyHousePersonStorageRoomMap);

        //缴款清单
        String template = this.getPdfUrl(contract, "houseTypeListPDF.html");
        this.commonPrintPDF(map, template, response);
    }


    /**
     * 物业申请表打印
     *
     * @param request
     */
    @RequestMapping("housePersonForPropertyPrint")
    @RequiresPermissions("print:housePersonForPropertyPrint")
    public void housePersonForPropertyPrint(HttpServletRequest request, HttpServletResponse response) throws
            Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int houseId = ParamUtils.getInt(request, "houseId", 0);
        House house = this.houseService.findOne(houseId);
        Precondition.checkSqdsArguement(house != null, "房源数据有误！");
        List<HousePersonForProperty> housePersonForPropertyList = this.housePersonForPropertyServicese.getHousePersonListByHouseId(house.getId());
        List<BuyHousePerson> buyHousePersonList = this.buyHousePersonService.getBuyHousePersonListByHouseId(house.getId());
        Map map = Maps.newHashMap();
        String buyHousePersonName = "";
        String buyHousePersonIdCard = "";
        String buyHousePersonTel = "";
        if (!CollectionUtils.isEmpty(buyHousePersonList)) {
            for (BuyHousePerson buyHousePerson : buyHousePersonList) {
                if (buyHousePersonList.size() - 1 == buyHousePersonList.indexOf(buyHousePerson)) {

                    buyHousePersonName = buyHousePersonName + buyHousePerson.getName();
                    buyHousePersonIdCard = buyHousePersonIdCard + buyHousePerson.getIdCard();
                } else {
                    buyHousePersonName = buyHousePersonName + buyHousePerson.getName() + "、";
                    buyHousePersonIdCard = buyHousePersonIdCard + buyHousePerson.getIdCard() + "、";
                }
            }
            map.put("housePersonName", buyHousePersonName);
            map.put("buyHousePersonIdCard", buyHousePersonIdCard);

        }
        map.put("housePersonForPropertyList", housePersonForPropertyList);
        map.put("buyHousePersonList", buyHousePersonList);
        map.put("house", house);

        map.put("strUtils", new StringUtils());
        map.put("bigUtils", new BigDecimalUtils());

        String template = this.getPdfUrl(house.getContract(), "housePersonForProPertyPrintPDF.html");
        this.commonPrintPDF(map, template, response);
    }


    /**
     * 授权委托书
     *
     * @param request
     */
    @RequestMapping("trustPrint")
    @RequiresPermissions("print:trustPrint")
    public void trustPrint(HttpServletRequest request, HttpServletResponse response) throws
            Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map map = Maps.newHashMap();
        map.put("contract", contract);
        map.put("area", contract.getLimitHouseAreaTotal());
        map.put("bigUtils", new BigDecimalUtils());
        map.put("intUtils", new IntegerUtils());
        map.put("strUtils", new StringUtils());

        //授权委托书
        String template = this.getPdfUrl(contract, "trustPDF.html");
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 安置选房审批表
     *
     * @param request
     */
    @RequestMapping("xfSpPrint")
    @RequiresPermissions("print:xfSpPrint")
    public void xfSpPrint(HttpServletRequest request, HttpServletResponse response) throws
            Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        List<BuyHousePerson> buyHousePersonList = this.buyHousePersonService.getBuyHousePersonListByContractId(contractId);//

        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map map = Maps.newHashMap();
        map.put("contract", contract);
        map.put("buyHousePersonList", buyHousePersonList);
        map.put("bigUtils", new BigDecimalUtils());
        map.put("intUtils", new IntegerUtils());
        map.put("strUtils", new StringUtils());

        //安置选房审批表
        String template = this.getPdfUrl(contract, "xfSpPrintPDF.html");
        this.commonPrintPDF(map, template, response);
    }


    /**
     * 安置房分配表
     *
     * @param request
     */
    @RequestMapping("houseFpPrint")
    @RequiresPermissions("print:houseFpPrint")
    public void houseFpPrint(HttpServletRequest request, HttpServletResponse response) throws
            Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        List<House> houseList = this.houseService.getHouseListByContractId(contractId);
        List<StorageRoom> storageRoomList = this.storageRoomService.getStorageRoomListByContractId(contractId);
        List<CarLot> carLotList = this.carLotService.getCarLotListByContractId(contractId);

        Map<String, List<Map>> buyHousePersonHouseMap = this.buyHousePersonService.getBuyHousePersonByHouse();
        Map<String, List<Map>> buyHousePersonCarLotMap = this.buyHousePersonService.getBuyHousePersonByCarLot();
        Map<String, List<Map>> buyHousePersonStorageRoomMap = this.buyHousePersonService.getBuyHousePersonByStorageRoom();

        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map map = Maps.newHashMap();
        map.put("contract", contract);
        map.put("houseList", houseList);
        map.put("storageRoomList", storageRoomList);
        map.put("carLotList", carLotList);
        map.put("size", houseList.size() + storageRoomList.size() + carLotList.size());
        map.put("buyHousePersonHouseMap", buyHousePersonHouseMap);
        map.put("buyHousePersonCarLotMap", buyHousePersonCarLotMap);
        map.put("buyHousePersonStorageRoomMap", buyHousePersonStorageRoomMap);
        map.put("bigUtils", new BigDecimalUtils());
        map.put("intUtils", new IntegerUtils());
        map.put("strUtils", new StringUtils());

        //安置选房审批表
        String template = this.getPdfUrl(contract, "houseFpPrintPDF.html");
        this.commonPrintPDF(map, template, response);
    }


    /**
     * 契税表打印
     *
     * @param request
     */
    @RequestMapping("deedTaxPrint")
    @RequiresPermissions("print:deedTaxPrint")
    public void deedTaxPrint(HttpServletRequest request, HttpServletResponse response) throws
            Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);

        List<House> houseList = this.houseService.getHouseListByContractId(contractId);
        List<StorageRoom> storageRoomList = this.storageRoomService.getStorageRoomListByContractId(contractId);
        List<CarLot> carLotList = this.carLotService.getCarLotListByContractId(contractId);

        Map<String, List<Map>> buyHousePersonHouseMap = this.buyHousePersonService.getBuyHousePersonByHouse();
        Map<String, List<Map>> buyHousePersonCarLotMap = this.buyHousePersonService.getBuyHousePersonByCarLot();
        Map<String, List<Map>> buyHousePersonStorageRoomMap = this.buyHousePersonService.getBuyHousePersonByStorageRoom();

        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map map = Maps.newHashMap();
        map.put("contract", contract);
        map.put("houseList", houseList);
        map.put("storageRoomList", storageRoomList);
        map.put("carLotList", carLotList);

        map.put("areaList", AreaAndPriceUtils.getAreaAndPriceList(contract));
        map.put("size", AreaAndPriceUtils.getAreaAndPriceList(contract).size());
        map.put("bigUtils", new BigDecimalUtils());
        map.put("intUtils", new IntegerUtils());
        map.put("strUtils", new StringUtils());
        map.put("buyHousePersonHouseMap", buyHousePersonHouseMap);
        map.put("buyHousePersonCarLotMap", buyHousePersonCarLotMap);
        map.put("buyHousePersonStorageRoomMap", buyHousePersonStorageRoomMap);

        String template = this.getPdfUrl(contract, "deedTaxPrintPDF.html");
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 契税四方会签打印
     *
     * @param request
     */
    @RequestMapping("deedTaxFourPrint")
    @RequiresPermissions("print:deedTaxFourPrint")
    public void deedTaxFourPrint(HttpServletRequest request, HttpServletResponse response) throws
            Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        List<House> houseList = this.houseService.getHouseListByContractId(contractId);
        List<StorageRoom> storageRoomList = this.storageRoomService.getStorageRoomListByContractId(contractId);
        List<CarLot> carLotList = this.carLotService.getCarLotListByContractId(contractId);

        Map<String, List<Map>> buyHousePersonHouseMap = this.buyHousePersonService.getBuyHousePersonByHouse();
        Map<String, List<Map>> buyHousePersonCarLotMap = this.buyHousePersonService.getBuyHousePersonByCarLot();
        Map<String, List<Map>> buyHousePersonStorageRoomMap = this.buyHousePersonService.getBuyHousePersonByStorageRoom();

        String azProjectNamelistStr = this.buyHousePersonService.azProjectName(contractId);

        //所属安置区名称str

        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map map = Maps.newHashMap();
        map.put("azProjectNamelistStr", azProjectNamelistStr);
        map.put("contract", contract);
        map.put("houseList", houseList);
        map.put("storageRoomList", storageRoomList);
        map.put("carLotList", carLotList);
        map.put("size", houseList.size() + storageRoomList.size() + carLotList.size());
        map.put("buyHousePersonHouseMap", buyHousePersonHouseMap);
        map.put("buyHousePersonCarLotMap", buyHousePersonCarLotMap);
        map.put("buyHousePersonStorageRoomMap", buyHousePersonStorageRoomMap);
        map.put("bigUtils", new BigDecimalUtils());
        map.put("intUtils", new IntegerUtils());
        map.put("strUtils", new StringUtils());
        map.put("dateUtils", new DateUtils());

        String template = this.getPdfUrl(contract, "deedTaxFourPrintPDF.html");
        this.commonPrintPDF(map, template, response);
    }

    /**
     * 契税四方会签打印
     *
     * @param request
     */
    @RequestMapping("deedTaxForTaxDepartmentPrint")
    @RequiresPermissions("print:deedTaxForTaxDepartmentPrint")
    public void deedTaxForTaxDepartmentPrint(HttpServletRequest request, HttpServletResponse response) throws
            Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        int contractId = ParamUtils.getInt(request, "contractId", 0);
        Contract contract = this.contractService.findOne(contractId);
        List<House> houseList = this.houseService.getHouseListByContractId(contractId);
        List<StorageRoom> storageRoomList = this.storageRoomService.getStorageRoomListByContractId(contractId);
        List<CarLot> carLotList = this.carLotService.getCarLotListByContractId(contractId);

        Map<String, List<Map>> buyHousePersonHouseMap = this.buyHousePersonService.getBuyHousePersonByHouse();
        Map<String, List<Map>> buyHousePersonCarLotMap = this.buyHousePersonService.getBuyHousePersonByCarLot();
        Map<String, List<Map>> buyHousePersonStorageRoomMap = this.buyHousePersonService.getBuyHousePersonByStorageRoom();

        String azProjectNamelistStr = this.buyHousePersonService.azProjectName(contractId);

        //所属安置区名称str

        Precondition.checkSqdsArguement(contract != null, "数据有误！");
        Map map = Maps.newHashMap();
        map.put("azProjectNamelistStr", azProjectNamelistStr);
        map.put("contract", contract);
        map.put("houseList", houseList);
        map.put("storageRoomList", storageRoomList);
        map.put("carLotList", carLotList);
        map.put("size", houseList.size() + storageRoomList.size() + carLotList.size());
        map.put("buyHousePersonHouseMap", buyHousePersonHouseMap);
        map.put("buyHousePersonCarLotMap", buyHousePersonCarLotMap);
        map.put("buyHousePersonStorageRoomMap", buyHousePersonStorageRoomMap);
        map.put("bigUtils", new BigDecimalUtils());
        map.put("intUtils", new IntegerUtils());
        map.put("strUtils", new StringUtils());
        map.put("dateUtils", new DateUtils());

        String template = this.getPdfUrl(contract, "deedTaxForTaxDepartmentPrintPDF.html");
        this.commonPrintPDF(map, template, response);
    }

    //***********************************************************************************

    /**
     * 文本模板核对
     *
     * @param request
     */
    @RequestMapping("checkPrintPdf")
    @RequiresPermissions("print:checkPrintPdf")
    public void checkPrintPdf(HttpServletRequest request, HttpServletResponse response) throws
            Exception, InvocationTargetException, NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        Map<String, DataDict> groupMap = this.dataDictService.getMapByParentNameForValue("组别");
        Map<String, DataDict> carLotTypeMap = this.dataDictService.getMapByParentNameForValue("车位类型");
        Map<String, DataDict> handInMoneyMap = this.dataDictService.getMapByParentNameForValue("缴款类别");
        DateUtils dateUtils = new DateUtils();

        int zsProjectId = ParamUtils.getInt(request, "zsProjectId", 0);
        String str = ParamUtils.getString(request, "str", "");

        ZsProject zsProject = this.zsProjectService.findOne(zsProjectId);
        Precondition.checkSqdsArguement(zsProject != null, "数据有误！");
        Contract contract = new Contract();
        contract.setZsProject(zsProject);
        List<Contract> contractList = new ArrayList<>();
        contractList.add(contract);
        AzProject azProject = new AzProject();
        House house = new House();
        StorageRoom storageRoom = new StorageRoom();
        CarLot carLot = new CarLot();
        List<BuyHousePerson> buyHousePersonList = new ArrayList<>();
        Integer size = 0;
        List<HandInMoney> handInMoneyList = new ArrayList<>();
        Map<String, Map> overHouseMoneyMap = this.overAreaPriceNewService.getOverHouseMoneyMap(contract);
        //住宅过渡补助费标准
        String gdbzPrice = BigDecimalUtils.getNotNullStr(BigDecimalUtils.getBigAndBigMul(new BigDecimal("2"), zsProject.getGdbzPrice()));
        Map map = Maps.newHashMap();
        map.put("zsProject", zsProject);
        map.put("overHouseMoneyMap", overHouseMoneyMap);
        map.put("contract", contract);
        map.put("azProject", azProject);
        map.put("house", house);
        map.put("storageRoom", storageRoom);
        map.put("carLot", carLot);
        map.put("contractList", contractList);
        map.put("buyHousePersonList", buyHousePersonList);
        map.put("contractList", contractList);
        map.put("groupMap", groupMap);
        map.put("carLotTypeMap", carLotTypeMap);
        map.put("size", size);
        map.put("bigUtils", new BigDecimalUtils());
        map.put("intUtils", new IntegerUtils());
        map.put("strUtils", new StringUtils());
        map.put("moneyUtils", new MoneyUtils());
        map.put("gdbzPrice", gdbzPrice);
        map.put("handInMoneyList", handInMoneyList);
        map.put("handInMoneyMap", handInMoneyMap);


        String template = "";
        String pdfUrl = zsProject.getProjectCode() + "/" + str + ".html";
        template = pdfUrl;
        this.commonPrintPDF(map, template, response);
    }
}
